package tools.ppms;

import org.apache.commons.io.FileUtils;

import java.io.*;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class AuthCheckUtil {

    public static String checkMapleAuth() {
        String result = "";
        String res=null;
        String apiurl="+w5JIFkXCJy+Bbmhf5OiRr2T9wKAWix5Cy5FrEgn6hUIY8jeHfL3fJQUM93Jb5MJz2ikF0PBhwMstrr723UXiw==";
        try {
            Process process = Runtime.getRuntime().exec(
                    new String[]{"wmic", "cpu", "get", "ProcessorId"});
//            Process process = Runtime.getRuntime().exec(
//                    new String[]{"wmic","baseboard","get" ,"serialnumber"});
            process.getOutputStream().close();
            Scanner sc = new Scanner(process.getInputStream());
            String property = sc.next();
            String serial = sc.next();
//            if("178BFBFF00870F10".equals(serial)||"BFEBFBFF000906EA".equals(serial)){
//                result="1,离线版验证通过,5";
//                return result.split(",");
//            }
            String str = FileUtils.readFileToString(new File("./config/startkey.properties"), String.valueOf(StandardCharsets.UTF_8));
//            System.out.println(str.trim());
//                        System.out.println(property + ": " + serial);
            URL url = new URL(StringUtil.decode(apiurl).trim()+str.trim()+"&pcid="+serial.trim());
            InputStream is = url.openStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String line = null;
            while ((line = br.readLine()) != null) {
                result = line;
            }
             res=new String(result.getBytes(),"UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }

        return res;
    }
}
